package com.bowen.security.rsa.factory;

import com.bowen.security.rsa.downstream.DownStreamClient;
import com.bowen.security.rsa.model.AuthRequest;
import com.bowen.security.rsa.upstream.UpStreamClient;

/**
 * 
 * @author Bowen
 * @since 2021-12-06 18:15:02
 */
public class RasFactory {

  /**
   * 上游加密
   * 
   * @param <T>  泛型
   * @param data 数据
   * @return 加密串
   */
  public <T extends AuthRequest> String upStreamEncoder(T data) {
    com.bowen.security.rsa.Client client = UpStreamClient.getUpStreamClient();
    return client.encryption(data);
  }

  /**
   * 下游解密
   * 
   * @param <T>   继承AuthRequest
   * @param clazz 值对象
   * @param data  加密串
   * @return 对象值
   */
  public <T extends AuthRequest> T downStreamDecoder(Class<T> clazz, String data) {
    com.bowen.security.rsa.Client client = new DownStreamClient();
    return client.decrypt(clazz, data);
  }

}
